# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=crypto++
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=r711.1160f41
pkgrel=1
pkgdesc="Crypto++ Library is a free C++ class library of cryptographic schemes."
arch=('any')
url="http://www.cryptopp.com/"
license=('Boost Software License 1.0')
options=('staticlibs' 'strip')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake" "git")
source=(${_realname}::"git+https://github.com/weidai11/cryptopp.git"
        libcrypto++.pc
        missing-sources.patch
        cryptopp-cmake.patch
        resolve-namespace-conflict.patch
        fix-test-linking.patch)
sha256sums=('SKIP'
            '50abc6e0746de6a8599e7a6b601619a1877bd100788fdb83e74558e9f22adef8'
            '749f76ce1049db24736e6aa7405bc890548c320f66c57f1c9bf4e6aa2ee49e50'
            'f58e2a1f6697868baf074eef96ff132adf1797f8cd2b8bb05c3d75eec112f599'
            '6e63acb2b3f76fda56bc7019b3bde4ab7f3ca209310bf4108d21e6c39b7fa0e9'
            '99e5bb3ba211c6155a19a170b7e498b904bf821f7d2aa46be06d08a87846fa17')

pkgver() {
  cd ${_realname}
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${_realname}
  sed -i -e 's/^CXXFLAGS/#CXXFLAGS/' GNUmakefile
  patch -p1 -i ${srcdir}/missing-sources.patch
  patch -p1 -i ${srcdir}/cryptopp-cmake.patch
  patch -p1 -i ${srcdir}/resolve-namespace-conflict.patch
  patch -p1 -i ${srcdir}/fix-test-linking.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  install -D -m644 ${srcdir}/${_realname}/License.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
